package 试题和试卷;

import GUI.organizePaperWindow;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class definitionAddItem extends questionAddItem {
    public definitionAddItem() {
    }

    public definitionAddItem(int n, question currentquestion) {

        super(n, currentquestion);
        detailButton.addActionListener(new detailListener());
        deleteButton.addActionListener(new deleteListener());

    }

    public class detailListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            organizePaperWindow.definitionQuestions.add((definitionQuestion) currentquestion);
            organizePaperWindow.questions.add((definitionQuestion) currentquestion);
            detailButton.setEnabled(false);
            deleteButton.setEnabled(true);
        }
    }
    public class deleteListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            //int size=organizePaperWindow.definitionQuestions.size();
            organizePaperWindow.definitionQuestions.removeIf(a -> currentquestion.getTitle().equals(a.getTitle()));
            organizePaperWindow.questions.removeIf(a ->currentquestion.getTitle().equals(a.getTitle()));
            /*for (int i=0;i<size;i++){
                if(currentquestion.getTitle().equals(organizePaperWindow.definitionQuestions.get(i).getTitle())){
                    organizePaperWindow.definitionQuestions.remove(i);
                    organizePaperWindow.questions.remove(i);
                }
            }*/
            detailButton.setEnabled(true);
            deleteButton.setEnabled(false);
        }
    }
}